package com.hk.service.order.impl;

import org.springframework.stereotype.Service;

import com.hk.commons.HqlFilter;
import com.hk.commons.LongId;
import com.hk.commons.ReqToModelHelper;
import com.hk.commons.entity.order.OrderInfo;
import com.hk.commons.entity.order.OrderStatements;
import com.hk.dao.base.impl.BaseServiceImpl;
import com.hk.service.order.IOrderStatements;

/**
 * 订单流水表
 * @author jeff
 *
 */
@Service
public class OrderStatementsImpl extends BaseServiceImpl<OrderStatements> implements IOrderStatements{
	
	@Override
	public OrderStatements findById(long id) {
		
		return getById(id);
	}

	@Override
	public Long add(OrderStatements model) {
		Long id = LongId.get();
		model.setId(id);
		
		//设置订单ID
		model.setOrderCreatedOn(System.currentTimeMillis());
		
		super.save(model);
		
		return id;
	}

	@Override
	public Long copyFromOrderFile(OrderInfo order) {
		OrderStatements orderStatements = new OrderStatements();
		ReqToModelHelper.copyReqValueToModel( order, orderStatements);
		orderStatements.setOrderId(order.getId());
		
		Long id = add(orderStatements);
		return id;
	}

	@Override
	public OrderStatements getByBrokerOrderNo(String brokerOrderNo){
		HqlFilter hqlFilter =  new HqlFilter();
		hqlFilter.addEQFilter("brokerOrderNo", brokerOrderNo);
		return getByFilter(hqlFilter);
		 
	}
	
}
